clear all;close all;clc;
Fd=40e3;
Td=1/Fd;
Tmod=0.03;
t=0:Td:Tmod;


S=cos(2*pi*(500+1*rand(1,1))*t);
Sf=fft(S);
T=Tmod+Td;
f=0:1/T:1/Td-1/T;
N=length(f);
figure;
plot(t,S);

[y,i]=max(abs(Sf));
f(i)



signal_clear = 0;
use_window=1;
if use_window
    yw = S .* parzenwin(N)';
else
    yw = S;
end
yfw = fft(yw);



yf_rej = yfw;
subplot(1,2,1)
stem(t, S);
xlabel('t, \mus');
ylabel('');

subplot(1,2,2)
stem(t, yw);
xlabel('t, \mus');
ylabel('y after window');

figure
subplot(1,2,2)
stem(f, abs(yfw));
xlabel('f, MHz');
ylabel('fft(y after window)');

xlim([0 1000 ])
subplot(1,2,1)
stem(f, abs(Sf))
xlabel('f, Hz');
ylabel('fft(S)');
xlim([0 1000 ])

